package com.beagle.njddapp.ui.presenter;

import com.beagle.njddapp.base.BasePresenter;
import com.beagle.njddapp.base.NjOwnerApiService;
import com.beagle.njddapp.base.RetrofitHttp;
import com.beagle.njddapp.bean.MessageHandleBean;
import com.beagle.njddapp.bean.MessageIdsBean;
import com.beagle.njddapp.net.BaseOilHttpResponse;
import com.beagle.njddapp.net.HttpResponseObserver;
import com.beagle.njddapp.net.RxSchedulers;
import com.beagle.njddapp.ui.view.MessageDetailView;
import com.beagle.njddapp.ui.view.OrderView;
import com.google.gson.Gson;

import okhttp3.RequestBody;

/**
 * @author hxx
 * @date 2021-03-02 22:33
 */
public class MessageDetailPresenter extends BasePresenter<MessageDetailView> {
    private NjOwnerApiService apiService;

    public MessageDetailPresenter() {
        retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
        //获取接口对象
        apiService = retrofit.create(NjOwnerApiService.class);
    }
    public void read(int [] ids){
        MessageIdsBean idsBean=new MessageIdsBean();
        idsBean.id=ids;
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),new Gson().toJson(idsBean));
        apiService.read(body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver() {
            @Override
            public void success(Object o) {

            }

            @Override
            public void error(int code, String message) {
                getView().onError(message);
            }
        });
    }


    public void dela(int id,String caozup){
        MessageHandleBean handleBean=new MessageHandleBean();
        handleBean.id=id;
        handleBean.data=caozup;
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),new Gson().toJson(handleBean));
        apiService.dealMessage(body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpResponse>() {
            @Override
            public void success(BaseOilHttpResponse o) {
                getView().dealSuccess(caozup);
            }

            @Override
            public void error(int code, String message) {
                getView().onError(message);
            }
        });
    }




}
